package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.WxMatrix;
import com.ysqcould.allocation.service.IWxMatrixService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信公众号矩阵Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/allocation/matrix")
public class WxMatrixController extends BaseController
{
    @Autowired
    private IWxMatrixService wxMatrixService;

    /**
     * 查询微信公众号矩阵列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxMatrix wxMatrix)
    {
        startPage();
        List<WxMatrix> list = wxMatrixService.selectWxMatrixList(wxMatrix);
        return getDataTable(list);
    }

    /**
     * 导出微信公众号矩阵列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:export')")
    @Log(title = "微信公众号矩阵", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxMatrix wxMatrix)
    {
        List<WxMatrix> list = wxMatrixService.selectWxMatrixList(wxMatrix);
        ExcelUtil<WxMatrix> util = new ExcelUtil<WxMatrix>(WxMatrix.class);
        util.exportExcel(response, list, "微信公众号矩阵数据");
    }

    /**
     * 获取微信公众号矩阵详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxMatrixService.selectWxMatrixById(id));
    }

    /**
     * 新增微信公众号矩阵
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:add')")
    @Log(title = "微信公众号矩阵", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMatrix wxMatrix)
    {
        wxMatrix.setAsId(getUserId());
        return toAjax(wxMatrixService.insertWxMatrix(wxMatrix));
    }

    /**
     * 修改微信公众号矩阵
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:edit')")
    @Log(title = "微信公众号矩阵", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMatrix wxMatrix)
    {
        return toAjax(wxMatrixService.updateWxMatrix(wxMatrix));
    }

    /**
     * 删除微信公众号矩阵
     */
    @PreAuthorize("@ss.hasPermi('allocation:matrix:remove')")
    @Log(title = "微信公众号矩阵", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxMatrixService.deleteWxMatrixByIds(ids));
    }
}
